home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 July: Mac OS SDK / Dev.CD Jul 00 SDK2.toast / Development Kits / Hardware / Mac OS USB DDK / Mac OS USB DDK 1.4.1 / Examples / USBTabletModule / USBTabletModuleCDM.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-04-25  |  5.7 KB  |  224 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        USBTabletModuleCDM.c
  3.  
  4.     Contains:    HID Emulation glue code between the ADB SHIM and the USB Wacom HID Module
  5.  
  6.     Version:    xxx put version here xxx
  7.  
  8.     Copyright:    © 1998 by Apple Computer, Inc., all rights reserved.
  9.  
  10. */
  11.  
  12. #include <Types.h>
  13. #include <Devices.h>
  14. #include <DriverServices.h>
  15. #include <CursorDevices.h>
  16. #include <USB.h>
  17.  
  18.  
  19. #include "USBTabletModule.h"
  20.  
  21. extern    usbWacomPBStruct myWacomPB;
  22.  
  23. void NotifyCursorDeviceManager(UInt32 refcon, void * theData)
  24. {
  25. #pragma unused (refcon)
  26.  
  27. USBHIDDataPtr    pWacomData;
  28. static UInt16     oldbuttons = 0;
  29. UInt16     changedbuttons = 0;
  30.  
  31. //    DebugStr("\pIn NotifyCursorDeviceManager");
  32.     pWacomData = (USBHIDDataPtr)theData;
  33.  
  34.     // Tell the Cursor Device Manager that we moved
  35.     if ((pWacomData->mouse.XDelta != 0) || (pWacomData->mouse.YDelta !=0))
  36.     {
  37.         if (pWacomData->mouse.XDelta > 127)
  38.             pWacomData->mouse.XDelta = 127;
  39.             
  40.         if (pWacomData->mouse.YDelta > 127)
  41.             pWacomData->mouse.YDelta = 127;
  42.             
  43.         if (pWacomData->mouse.YDelta < -127)
  44.             pWacomData->mouse.YDelta = -127;
  45.             
  46.         if (pWacomData->mouse.XDelta < -127)
  47.             pWacomData->mouse.XDelta = -127;
  48.         CursorDeviceMove(myWacomPB.pCursorDeviceInfo, pWacomData->mouse.XDelta, pWacomData->mouse.YDelta);
  49.     }
  50.     
  51.     // Update with the state of the buttons.
  52.     pWacomData->mouse.buttons &= 0x03;
  53.     changedbuttons = oldbuttons ^ pWacomData->mouse.buttons;
  54.     if (changedbuttons)
  55.     {
  56.         CursorDeviceButtons(myWacomPB.pCursorDeviceInfo, (short)pWacomData->mouse.buttons);
  57.     }
  58.     oldbuttons = pWacomData->mouse.buttons;
  59. }
  60.  
  61. OSStatus API_InstallInterrupt(HIDInterruptProcPtr HIDInterruptFunction, UInt32 refcon)
  62. {
  63.     USBExpertStatus(myWacomPB.deviceRef, "\pUSBHIDWacomModule: Demo Mode Disabled (interrupt service routine installed)", myWacomPB.deviceRef);
  64.     myWacomPB.refcon = refcon;
  65.     myWacomPB.pSHIMInterruptRoutine = HIDInterruptFunction;
  66.     return noErr;
  67. }
  68.  
  69. OSStatus API_PollDevice(void)
  70. {
  71.     return kUSBInternalErr;
  72. }
  73.  
  74. OSStatus API_ControlDevice(UInt32 theControlSelector, void * theControlData)
  75. {
  76. #pragma unused (theControlData)
  77.  
  78.     switch (theControlSelector)
  79.     {
  80.         case kHIDRemoveInterruptHandler:
  81.             myWacomPB.refcon = nil;
  82.             myWacomPB.pSavedInterruptRoutine = nil;
  83.             myWacomPB.pSHIMInterruptRoutine = nil;
  84.             break;
  85.             
  86.         case kHIDEnableDemoMode:
  87.             USBExpertStatus(myWacomPB.deviceRef, "\pUSBHIDWacomModule: Demo Mode Enabled", myWacomPB.deviceRef);
  88.             
  89.             if (myWacomPB.pCursorDeviceInfo == 0)
  90.             {
  91.                 myWacomPB.pCursorDeviceInfo = &myWacomPB.cursorDeviceInfo;
  92.                 CursorDeviceNewDevice(&myWacomPB.pCursorDeviceInfo);
  93.                 
  94.                 CursorDeviceSetAcceleration(myWacomPB.pCursorDeviceInfo, (Fixed)(1<<16));
  95.                 
  96.                 CursorDeviceSetButtons(myWacomPB.pCursorDeviceInfo, 2);            // should actually be set by reading
  97.                                                                                 // the HID descriptor, but lacking
  98.                                                                                 // a parser, we'll just force it
  99.                                                                                 // this way.
  100.                 CursorDeviceButtonOp(myWacomPB.pCursorDeviceInfo, 0, kButtonSingleClick, 0L);
  101.                 CursorDeviceButtonOp(myWacomPB.pCursorDeviceInfo, 1, kButtonSingleClick, 0L);
  102.                 CursorDeviceUnitsPerInch(myWacomPB.pCursorDeviceInfo, (Fixed)(myWacomPB.unitsPerInch));
  103.             }
  104.         
  105.             myWacomPB.pSavedInterruptRoutine = myWacomPB.pSHIMInterruptRoutine;
  106.             myWacomPB.pSHIMInterruptRoutine = NotifyCursorDeviceManager;
  107.             break;
  108.  
  109.         case kHIDDisableDemoMode:
  110.             USBExpertStatus(myWacomPB.deviceRef, "\pUSBHIDWacomModule: Demo Mode Disabled", myWacomPB.deviceRef);
  111.             if (myWacomPB.pCursorDeviceInfo != 0)
  112.             {
  113.                 CursorDeviceDisposeDevice(myWacomPB.pCursorDeviceInfo);
  114.                 myWacomPB.pCursorDeviceInfo = 0;
  115.             }
  116.             myWacomPB.pSHIMInterruptRoutine = myWacomPB.pSavedInterruptRoutine;
  117.             break;
  118.  
  119.         default:
  120.             return paramErr;
  121.     }
  122.     return noErr;
  123. }
  124.  
  125.  
  126.  
  127. OSStatus API_GetDeviceInfo(UInt32 theInfoSelector, void * theInfo)
  128. {
  129. HIDInterruptProcPtr * pHIDIntProcPtr;
  130. UInt32 * pUnits;
  131. UInt32 * pInterruptRefcon;
  132.  
  133.     switch (theInfoSelector)
  134.     {
  135.         case kHIDGetDeviceUnitsPerInch:
  136.             pUnits = (UInt32*)theInfo;
  137.             *pUnits = (UInt32)(myWacomPB.unitsPerInch);
  138.             break;
  139.             
  140.             
  141.         case kHIDGetInterruptHandler:
  142.             pHIDIntProcPtr = (HIDInterruptProcPtr *)theInfo;     
  143.             *pHIDIntProcPtr = myWacomPB.pSHIMInterruptRoutine;
  144.             break;
  145.  
  146.         case kHIDGetInterruptRefcon:
  147.             pInterruptRefcon = (UInt32 *)theInfo;
  148.             *pInterruptRefcon = myWacomPB.refcon;
  149.             break;
  150.         
  151.         default:
  152.             return paramErr;
  153.     }
  154.     return noErr;
  155. }
  156.  
  157. OSStatus API_EnterPolledMode(void)
  158. {
  159.     return unimpErr;
  160. }
  161.  
  162. OSStatus API_ExitPolledMode(void)
  163. {
  164.     return unimpErr;
  165. }
  166.  
  167. void ProcessInterruptReport(UInt32 devicetype, UInt8 hidReport[])
  168. {
  169. #pragma unused (devicetype)
  170.  
  171. WacomReport        *pTheWacomReport;
  172. USBHIDData        theWacomData;
  173.  
  174. static    UInt16    prevXPosition = 0;
  175. static    UInt16    prevYPosition = 0;
  176.  
  177. UInt16            myXPosition, myYPosition;
  178. SInt16            myXDelta, myYDelta;
  179.  
  180.     pTheWacomReport = (WacomReport*)hidReport;
  181.     
  182.     pTheWacomReport->buttons &= 0x7f;
  183.     if (pTheWacomReport->buttons)
  184.     {
  185.         theWacomData.mouse.buttons = 0x01;
  186.     }
  187.     else
  188.     {
  189.         theWacomData.mouse.buttons = 0;
  190.     }
  191.     
  192.     myXPosition = pTheWacomReport->xPosition;
  193.     myYPosition = pTheWacomReport->yPosition;
  194.     
  195.     myXDelta = (SInt16)(myXPosition - prevXPosition);
  196.     myYDelta = (SInt16)(myYPosition - prevYPosition);
  197.     
  198.     prevXPosition = myXPosition;
  199.     prevYPosition = myYPosition;
  200.     
  201.     theWacomData.mouse.XDelta = (SInt16)myXDelta;
  202.     theWacomData.mouse.YDelta = (SInt16)myYDelta;
  203.     
  204.     if (myWacomPB.pSHIMInterruptRoutine)
  205.     {
  206.         (*myWacomPB.pSHIMInterruptRoutine)(myWacomPB.refcon, (void *)&theWacomData);
  207.     }
  208. }
  209.  
  210. USBHIDModuleDispatchTable TheHIDModuleDispatchTable =
  211. {
  212.     (UInt32)0,
  213.     (USBHIDInstallInterruptProcPtr)API_InstallInterrupt,
  214.     (USBHIDPollDeviceProcPtr)API_PollDevice,
  215.     (USBHIDControlDeviceProcPtr)API_ControlDevice,
  216.     (USBHIDGetDeviceInfoProcPtr)API_GetDeviceInfo,
  217.     (USBHIDEnterPolledModeProcPtr)API_EnterPolledMode,
  218.     (USBHIDExitPolledModeProcPtr)API_ExitPolledMode
  219. };
  220.  
  221. CursorDevicePtr gUSBWacom;
  222. CursorDevice    ourDevice;
  223.  
  224.